home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Scheduling / Cassandra / Source / DayText.m < prev    next >
Encoding:
Text File  |  1991-08-18  |  3.4 KB  |  157 lines

  1. //
  2. // DayText.m
  3. // Copyright (c) 1991 by Jiro Nakamura 
  4. // All rights reserved
  5. //
  6. //    by Jiro Nakamura (jiro@shaman.com)
  7. //
  8. // RCS Information
  9. // Revision Number->    $Revision: 1.3 $
  10. // Last Revised->    $Date: 91/02/17 22:03:21 $
  11. //
  12. static char rcsid[] = "$Id: WeekWindow.m,v 1.3 91/02/17 22:03:21 jiro Exp Locker: jiro $";
  13.  
  14. #import "Global.h"
  15. #import "Event.h"
  16. #import "calendar.h"    // for ascMyDate()
  17. #import "Cassandra.h"    
  18. #import "DayText.h"
  19.  
  20. #import <sys/file.h>
  21. #import <libc.h>
  22. #import <strings.h>
  23.  
  24.  
  25. @implementation DayText
  26.  
  27. - setDate: (struct tm *) date andPriority: (int) pr
  28. {
  29.     today = *date;
  30.     priorityCutOff = pr;
  31.     [self updateText];
  32.     return self;
  33. }
  34.  
  35. - updateText
  36. {
  37.     NXStream *output; 
  38.     Event *ev;
  39.     int eventCount;
  40.     int day, temp;
  41.     extern const char *shortMonths[12], *shortWeekDays[7];
  42.  
  43.     fixTmStructure( &today);
  44.         
  45.     // We want to read the eventFile pointed to by global 
  46.     ev = [Event newAt:[[NXApp global] eventFile]];
  47.  
  48.     // We need a temporary memory stream to store the queue.
  49.     if( (output = NXOpenMemory( NULL, 0, NX_READWRITE)) == NULL)
  50.         {
  51.         fprintf(stderr,"%s: Couldn't open memory stream for "
  52.             "Week Window queue scrollview. FATAL ERRROR.\n",
  53.             PROGNAME);
  54.         exit(1) ;
  55.         }
  56.         
  57.     [ev firstEvent];                
  58.     day = [ev mday];
  59.     if( dayCompare( &today, (struct tm *) timeNow()) == -1)
  60.         day = -2;        
  61.     else
  62.         {        
  63.         while( [ev present] != 0 &&
  64.             dayCompare( [ev time], &today ) == -1 )
  65.             [ev readEvent : [ev next]];     
  66.  
  67.         if( ([ev mday] != today.tm_mday) || 
  68.             ([ev mon]  != today.tm_mon) || 
  69.             ([ev year] != today.tm_year))
  70.                 day = -1;
  71.         else    
  72.             day = [ev mday];
  73.         }
  74.         
  75.     NXPrintf(output, "{\\rtf0\\ansi{\\fonttbl\\f0\\fmodern "
  76.         "%s;}\\fs%.0f\n",
  77.         [[NXApp global] fontName], [[NXApp global] fontSize] * 2);
  78.  
  79.     NXPrintf(output, "{\\f0\\b %s %s %2d\\par}\n", 
  80.         shortWeekDays[today.tm_wday],
  81.         shortMonths[today.tm_mon], today.tm_mday);
  82.  
  83.     eventCount = 0;
  84.                 
  85.     /* Print all events for today regardless of priority */
  86.     while ( [ev present] != 0 && [ev mday] == day)
  87.         {
  88.         if( [ev priority] < priorityCutOff)
  89.             {
  90.             [ev readEvent : [ev next]];     
  91.             eventCount++;
  92.             continue;
  93.             }
  94.             
  95.         if( [ev priority] > [[NXApp global] highPriority])
  96.             NXPrintf(output, "{\\f0\\b ");
  97.         else
  98.             NXPrintf(output, "{\\f0 ");
  99.  
  100.         if( [[NXApp global] militaryTime])
  101.             NXPrintf(output, "\\par {\\f0\\b %2d:%02d}"
  102.                 "{\\par \\li360 %s\\par}}\n", 
  103.                 [ev hour], [ev min], [ev message]);
  104.         else
  105.             {
  106.             temp = [ev hour];
  107.             if( temp > 12 ) temp -= 12;
  108.             if( temp == 0 ) temp = 12;            
  109.             NXPrintf(output, "\\par{\\f0\\b %2d:%02d %s}"
  110.                 "{\\par \\li360 %s\\par}}\n", 
  111.                     temp,    [ev min], 
  112.                     ([ev hour]>11)?"pm":"am", 
  113.                     [ev message]);
  114.             }
  115.         [ev readEvent : [ev next]];     
  116.         }   
  117.  
  118.     if( [ev present] == 0 || day <  0)
  119.         {
  120.         if( day == -2)
  121.             NXPrintf(output,  "{\\f0\\par Ancient history.}\n");
  122.         else
  123.             NXPrintf(output, "{\\f0\\par No events.}\n");
  124.         }
  125.     
  126.     if( eventCount > 0)    // Number of invisible events
  127.         NXPrintf(output, "{\\par (%d hidden)\\par}\n", 
  128.                     eventCount);
  129.                     
  130.     [ev free];
  131.                     
  132.     NXPrintf(output, "}\n");    
  133.  
  134.     NXSeek(output, 0, NX_FROMSTART);
  135.     [self readRichText: output]; 
  136.     NXSaveToFile( output, "/tmp/casdebug.rtf");
  137.     NXCloseMemory(output, NX_FREEBUFFER); 
  138.     
  139.     [self hideCaret];    // for some reason the Text
  140.                 
  141.     return self;
  142. }
  143.  
  144. - defaultsDidChange: sender
  145. {
  146.     #ifdef DEBUG
  147.         fprintf(stderr,"Defaults changed.... Overview compensating\n");
  148.     #endif
  149.     
  150.     militaryTime     = [[NXApp global] militaryTime];
  151.     
  152.     [self updateText];
  153.     return self;
  154. }
  155.  
  156. @end
  157.